const KoaRouter = require('@koa/router')
const { upload, create, update, remove, restore, findAll } = require('../controller/goods.controller')
const { auth, hadAdminPermission } = require('../middleware/auth.middleware')
const { validator } = require('../middleware/goods.middleware')
const goodsRouter = new KoaRouter({ prefix: '/goods' })
//商品图片上传
goodsRouter.post('/upload', auth, hadAdminPermission, upload)
//发布商品
goodsRouter.post('/', auth, hadAdminPermission, validator, create)
//修改商品信息
goodsRouter.put('/:id', auth, hadAdminPermission, validator, update)

//硬删除商品信息
goodsRouter.delete('/:id', auth, hadAdminPermission, remove)
// 软删除接口(商品下架)
goodsRouter.post('/:id/off', auth, hadAdminPermission, remove)
// 商品上架
goodsRouter.post('/:id/on', auth, hadAdminPermission, restore)

// 商品列表
goodsRouter.get('/', findAll)
module.exports = goodsRouter